package com.smallyang.controller;

import com.smallyang.domain.ResponseResult;
import com.smallyang.domain.dto.AddArticleDto;
import com.smallyang.domain.dto.ArticleDto;
import com.smallyang.domain.entity.Article;
import com.smallyang.domain.vo.ArticleVo;
import com.smallyang.domain.vo.BarVo;
import com.smallyang.domain.vo.PageVo;
import com.smallyang.service.ArticleService;
import com.smallyang.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨森
 * @description:
 * @date 2023年05月21日 18:03
 */
@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult list(Article article, Integer pageNum, Integer pageSize)
    {
        PageVo pageVo = articleService.selectArticlePage(article,pageNum,pageSize);
        return ResponseResult.okResult(pageVo);
    }

    @GetMapping("/{id}")
    public ResponseResult getInfo(@PathVariable("id") Long id){
        ArticleVo article = articleService.getInfo(id);
        return ResponseResult.okResult(article);

    }
    @PutMapping()
    public ResponseResult updateArticle(@RequestBody ArticleDto updateArticle){
        articleService.updateArticle(updateArticle);
        return ResponseResult.okResult();
    }

//    @DeleteMapping("/{id}")
//    public ResponseResult delete(@PathVariable Long id){
//        articleService.removeById(id);
//        return ResponseResult.okResult();
//    }

    @DeleteMapping("/{id}")
    public ResponseResult<Object> deleteArticle(@PathVariable List<Long> id){
        articleService.deleteArticle(id);
        return ResponseResult.okResult();
    }

//

}
